package dao.impl;

import dao.UserDao;
import org.apache.ibatis.session.SqlSession;
import pojo.User;
import util.MyBatisUtil;

import java.util.List;

public class UserDaoImpl implements UserDao {
    @Override
    public int addUser(User user) {
        //return MyBatisUtil.getSession().getMapper(UserDao.class).addUser(user);
        SqlSession session=MyBatisUtil.getSession();
        int result =session.getMapper(UserDao.class).addUser(user);
        session.commit();
        return result;
    }

    @Override
    public List<User> findAll(String name, String pass,int offset,int pageSize) {
        return MyBatisUtil.getSession().getMapper(UserDao.class).findAll(name,pass,offset,pageSize);
    }

    @Override
    public User findById(int id) {
        return MyBatisUtil.getSession().getMapper(UserDao.class).findById(id);
    }
    public int updateUser(User user){
        SqlSession session=MyBatisUtil.getSession();
        int result =session.getMapper(UserDao.class).updateUser(user);
        session.commit();
        return result;
    }

    @Override
    public int deleteUserById(Integer id) {
        SqlSession session=MyBatisUtil.getSession();
        int result =session.getMapper(UserDao.class).deleteUserById(id);
        session.commit();
        return result;
    }

    @Override
    public int count(User user) {
        return MyBatisUtil.getSession().getMapper(UserDao.class).count(user);
    }
}